package beta;

import javax.microedition.lcdui.Display;
import javax.microedition.midlet.MIDlet;

public class ScreenManager
{
    static Theme currentTheme = null;
    static Screen currentScreen = null;
    
    static boolean fullScreen = false;
    
    private static MinUICanvas canvas = null;
    static MIDlet midlet = null;
    
    public static void init(MIDlet m)
    {
        if(canvas != null)
            throw new IllegalStateException("ScreenManager już zainicjowany.");
        midlet = m;
        canvas = new MinUICanvas();
        
        currentTheme = new Theme();
        canvas.update();
    }
    
    public static void takeOver()
    {
        if(canvas == null)
            throw new IllegalStateException("ScreenManager nie jest zainicjowany.");
        Display.getDisplay(midlet).setCurrent(canvas);
    }
    
    public static int getScreenWidth()
    {
        return canvas.getScreenWidth();
    }
    
    public static int getScreenHeight(boolean whole)
    {
        return canvas.getScreenHeight();
    }
    
    public static void setCurrentTheme(Theme theme)
    {
        if(theme == null)
            throw new IllegalArgumentException("theme nie może być null.");
        currentTheme = theme;
        canvas.repaint();
    }
    
    public static Theme getCurrentTheme()
    {
        return currentTheme;
    }
    
    public static void setCurrentScreen(Screen screen)
    {
        if(currentScreen != null)
            currentScreen.hideNotify();
        currentScreen = screen;
        canvas.update();
        if(currentScreen != null)
            currentScreen.showNotify();
        canvas.repaint();
    }
    
    public static Screen getCurrentScreen()
    {
        return currentScreen;
    }
    
    public static void setFullScreen(boolean value)
    {
        fullScreen = value;
        canvas.update();
        canvas.repaint();
    }
    
    public static boolean isFullScreen()
    {
        return fullScreen;
    }
    
    public static void callRepaint()
    {
        canvas.repaint(MinUICanvas.SCREEN);
    }
    
    
}
